package com.china08.yxyapi.api.manage.sch.platform.xiaoben.catalog;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lessons.YxyLessonsSchoolCatalog;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.repository.db.YxyLessonsSchoolCatalogRepository;

/**
 * 校本课程--删除子分类
 * 
 * @author LiuWeidong
 *
 */

@CrossOrigin
@RestController
public class XiaobenCatalogTwoDelController extends YxyApiBaseController {

    @Autowired
    private YxyLessonsSchoolCatalogRepository yxyLessonsSchoolCatalogRepository;

    // @Autowired
    // private YxyLessonsSchoolLessonRepository
    // yxyLessonsSchoolLessonRepository;

    @RequestMapping(value = "/api_yw/manage/sch/platform/xiaoben/catalog/two/del", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void process(HttpServletRequest request,
            HttpServletResponse response, @RequestBody ReqModel model) {

        String idTwo = model.idTwo;

        // List<YxyLessonsSchoolLesson> yxyLessonsSchoolLessonsLst =
        // yxyLessonsSchoolLessonRepository
        // .findByCatalogId2(idTwo);
        // Assert.isTrue(yxyLessonsSchoolLessonsLst.size() == 0,
        // "您该分类下面有课程，请先删除课程再来删除分类！");

        YxyLessonsSchoolCatalog yxyLessonsSchoolCatalogs = yxyLessonsSchoolCatalogRepository
                .findById(idTwo);
        if (yxyLessonsSchoolCatalogs != null) {
            yxyLessonsSchoolCatalogRepository.delete(yxyLessonsSchoolCatalogs);
        }

    }

    /** 请求参数 */
    protected static class ReqModel extends YxyApiReqModel {

        // 子分类ID
        public String idTwo;

    }
}
